package com.zzqstart.cateservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzqstart.cateservice.controller.remote.consume.UcenRemoteController;
import com.zzqstart.cateservice.entity.CateRecipe;
import com.zzqstart.cateservice.service.CateRecipeService;
import com.zzqstart.commonutils.R;
import com.zzqstart.commonutils.entity.UcenterMember;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ClassName: CateIndexController
 * Package: com.zzqstart.cateservice.controller.front
 * Description:
 *
 * @Author zzqstart
 * @Create 2023-03-06 22:05
 * @Version 1.0
 */
@RestController
@RequestMapping("/cateservice/front")
@Api(tags = "首页菜谱，厨师显示")
public class CateIndexController {
    @Autowired
    private UcenRemoteController ucenRemoteController;
    @Autowired
    private CateRecipeService cateRecipeService;


    @GetMapping("/index")
    @Cacheable(key = "'selectIndexList'", value = "data")
    @ApiOperation(value = "获取首页菜谱，厨师")
    public R getIndexInfo() {
        List<CateRecipe> recipeList = cateRecipeService.getIndexRecipeList();

        List<UcenterMember> memberList = ucenRemoteController.getMemberList();

        return R.ok().data("recipeList", recipeList).data("memberList",memberList);
    }

    @GetMapping("/searchInfo/{page}/{limit}/{inputValue}")
    @ApiOperation(value = "搜索栏搜索功能")
    public R searchInfo(@PathVariable long page,@PathVariable long limit,@PathVariable(required = false) String inputValue) {
        Map<String,Object> map = cateRecipeService.pageBySearch(page,limit,inputValue);
        return R.ok().data(map);
    }
}
